package com.spirng.leetcode.day01;

public class Array2_3 {
    public static void main(String[] args) {
isPerfectSquare(16);
    }
    public int mySqrt(int x) {
        int l=0;
        int r=x;
        while (l<=r){
            int middle=(l+r)/2;
            if(middle*middle<x){
                return middle;
            }
            if(middle*middle>x){
                r=middle-1;
            }
            else {
                return middle;
            }
        }
        return -1;
    }
    public static boolean isPerfectSquare(int num) {
      int l=0;
      int r=num;
      while (l<=r){
          int mid=l+(r-l)/2;
          if(mid*mid>num){
              r=mid-1;
          }
          if(mid*mid<num){
              l=mid+1;
          }
          if(mid*mid==num){
              return true;
          }
      }
      return false;
    }
}
